package com.catmiao.spark.rdd.operator.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_action
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/22 22:47
 */
object RDD_Operator_04_action {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)

    //    val rdd = sparkContext.makeRDD(List(1,2,3,4),2)
    val rdd = sparkContext.makeRDD(List(
      ("a",1),("a",2),("a",3),
      ("b",1),("c",2),("d",3),
    ))


    // 统计每个值出现的次数
//    val result: collection.Map[Int, Long] = rdd.countByValue()
    val result: collection.Map[String, Long] = rdd.countByKey()

    println(result)

    sparkContext.stop()

  }

}
